//
//  RHUserManualCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/30.
//

#import "RHUserManualCell.h"
@interface RHUserManualCell()



@end
@implementation RHUserManualCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}
-(void)setupUI{
    self.contentView.backgroundColor = CFTabViewBgColor;
    UIView *top_bgView = kView;
    top_bgView.backgroundColor = [UIColor whiteColor];
    top_bgView.layer.cornerRadius = 8;
    top_bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:top_bgView];
    [top_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(0);
        make.right.mas_offset(-15);
       
    }];
    
    NSArray *titles = @[@"账号管理".rh_localized,@"电站管理".rh_localized,@"设备管理".rh_localized,@"企业管理".rh_localized,@"联系我们".rh_localized];

    __block CGFloat item_w = (kUI_WINDOW_W - 30 - 30-15)/2;
    __block CGFloat item_h = item_w*0.515;
    __block UIView *lastView;
    kWeakSelf;
    [titles enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *item_bgView = [[UIView alloc]init];
        item_bgView.backgroundColor = kCOLOR_HEX(@"F6F8FA");
        item_bgView.layer.cornerRadius = 8;
        item_bgView.layer.masksToBounds = YES;
        [top_bgView addSubview:item_bgView];
        
        UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"user_guide_%ld",idx]]];
        [item_bgView addSubview:img];
         
        QMUILabel *titleLab = [[QMUILabel alloc]init];
        titleLab.numberOfLines = 0;
        titleLab.text = titles[idx];
        titleLab.font = [UIFont boldSystemFontOfSize:13];
        titleLab.textColor = kCOLOR_HEX(@"3F4443");
        [item_bgView addSubview:titleLab];
        
        
        QMUIButton *btn = [[QMUIButton alloc]init];
        [item_bgView addSubview:btn];
        [[btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
            if(weakSelf.clickItemBlock){
                weakSelf.clickItemBlock(idx);
            }
        }];
        
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.size.equalTo(@(CGSizeMake(kScaleW(45), kScaleW(45))));
            make.centerY.mas_offset(0);
        }];
        
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_offset(-15);
            make.left.equalTo(img.mas_right).offset(15);
            make.centerY.mas_offset(0);
        }];
        
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
        }];
        
        if(idx == 0){
            [item_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.mas_offset(15);
                make.width.offset(item_w);
                make.height.offset(item_h);
            }];
        }else{
            if(idx%2==0){
                [item_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_offset(15);
                    make.top.equalTo(lastView.mas_bottom).offset(15);
                    make.size.equalTo(lastView);
                }];
            }else{
                [item_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(lastView.mas_right).offset(15);
                    make.top.equalTo(lastView);
                    make.size.equalTo(lastView);
                }];
            }
        }
        lastView = item_bgView;
    }];
    
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-15);
    }];
    
    UIView *onlineServerView = kView;
    onlineServerView.backgroundColor = kCOLOR_HEX(@"E0F6EF");
    onlineServerView.layer.cornerRadius = 8;
    onlineServerView.layer.masksToBounds = YES;
    [self.contentView addSubview:onlineServerView];
    
    UIImageView *serverIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"server_ consult"]];
    [onlineServerView addSubview:serverIcon];
    
    QMUILabel *serverTitleLab = [[QMUILabel alloc]init];
    serverTitleLab.text = @"在线服务".rh_localized;
    serverTitleLab.font = [UIFont systemFontOfSize:15];
    serverTitleLab.textColor = kCOLOR_HEX(@"38704E");
    [onlineServerView addSubview:serverTitleLab];
    
    QMUILabel *serverSubTitleLab = [[QMUILabel alloc]init];
    serverSubTitleLab.text = @"品牌等问题，官方在线答疑".rh_localized;
    serverSubTitleLab.font = [UIFont systemFontOfSize:12];
    serverSubTitleLab.textColor = [UIColor colorWithHexString:@"38704E" alpha:0.8];
    serverSubTitleLab.numberOfLines = 0;
    [onlineServerView addSubview:serverSubTitleLab];
    
    QMUIButton *serverBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    serverBtn.layer.cornerRadius = 15;
    serverBtn.layer.masksToBounds = YES;
    serverBtn.backgroundColor = kCOLOR_HEX(@"F8D151");
    [serverBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    serverBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [serverBtn setTitle:@"去咨询".rh_localized forState:UIControlStateNormal];
    [onlineServerView addSubview:serverBtn];
    
    [onlineServerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(top_bgView.mas_bottom).offset(15);
        make.bottom.mas_offset(-15);
        make.height.offset(kScaleW(80));
    }];
    
    [serverIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(10);
        make.bottom.mas_offset(-10);
        make.width.equalTo(serverIcon.mas_height);
    }];
    
    [serverTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(serverIcon.mas_right).offset(10);
        make.right.equalTo(serverBtn.mas_left).offset(-15);
        make.bottom.equalTo(onlineServerView.mas_centerY).offset(-5);
    }];
    
    [serverSubTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(serverTitleLab);
        make.right.equalTo(serverBtn.mas_left).offset(-15);
        make.top.equalTo(onlineServerView.mas_centerY).offset(5);
    }];
    
    [serverBtn sizeToFit];
    [serverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(serverBtn.width+15);
        make.height.offset(30);
        make.right.mas_offset(-15);
        make.centerY.mas_offset(0);
    }];
}
@end
